home *** CD-ROM | disk | FTP | other *** search
- Path: red.seas.upenn.edu!son
- From: son@red.seas.upenn.edu (Sonny)
- Newsgroups: comp.lang.c++
- Subject: file processing...
- Date: 21 Mar 1996 06:00:08 GMT
- Organization: University of Pennsylvania
- Message-ID: <4iqr98$i3p@netnews.upenn.edu>
- NNTP-Posting-Host: red.seas.upenn.edu
- X-Newsreader: TIN [version 1.2 PL2-upenn1.3]
-
- I want to read the 1st line of a text file into an array. The only way I know of to
- detect the end of a line is by checking for "\n", but the code I wrote does not seem
- be detecting it. Here is the code...
-
- #include<fstream.h>
- #include<iostream.h>
- #include<String.h>
-
- int readf(char array[],char *);
- int readf (char array[], char *filename)
- {
- int i=0;
- char c;
-
- ifstream inFile(filename, ios::in);
- while (inFile >> c)
- if (c!="\n") /*This line is giving me problem. It doesn't even compile */
- array[i++]=c;
- else
- break;
- return i;
-
- }
-
- void main(int argc,char *argv[])
- {
- int i;
- char array[50];
- i=readf(array,"gro");
-
- for(int c=0;c<i;c++)
- cout<<array[c];
- cout<<"\n";
- }
-
- --
-